---
import { Code as SCode } from '@astrojs/starlight/components'

import fs from 'node:fs/promises';

interface Props {
  file: string;
  language?: string;
  meta?: string;
}

const { file, language, meta } = Astro.props;
const fileNamePath = '../' + file;
const fileEtension = file.split('.').pop() ?? 'js';
const code = await fs.readFile(fileNamePath, 'utf-8');
const lang  = language ?? fileEtension;
const metaa =  `title="${file}"` + (meta ? ` ${meta}` : '')


---

<SCode code={code} lang={lang} meta={metaa} />

<!-- <SCode code="console.log('Hello world!')" lang="js" /> -->
